package unclassified.medium;

public class SimpleBankSystem_2043 {

    long[] bank;
    public SimpleBankSystem_2043(long[] bank){
        this.bank = bank;
    }

    public boolean check(int account) {
        return 1 <= account && account <= bank.length;
    }

    public boolean transfer(int account1, int account2, long money) {
        if (!check(account1) || !check(account2)) {
            return false;
        }
        if (bank[account1 - 1] < money) {
            return false;
        }
        bank[account1 - 1] = bank[account1 - 1] - money;
        bank[account2 - 1] = bank[account2 - 1] + money;
        return true;
    }

    public boolean deposit(int account, long money) {
        if (!check(account)) {
            return false;
        }
        bank[account - 1] = bank[account - 1] + money;
        return true;
    }

    public boolean withdraw(int account, long money) {
        if (!check(account)) {
            return false;
        }
        if (bank[account - 1] < money) {
            return false;
        }
        bank[account - 1] = bank[account - 1] - money;
        return true;
    }
}
